﻿using Sunny.UI;
using System.Diagnostics;
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using CoreShop.Model;
using Newtonsoft.Json;
using CoreShop.Library;
using CoreShop.Model.FromBody;

namespace CoreShop.App
{
    public partial class frmReportPage : UIAsideHeaderMainFooterFrame
    {
        public int mPageIndex = 1001;

        public frmReportPage()
        {
            InitializeComponent();
            this.ShowFullScreen = AppConstVars.showFullScreen;
            //设置关联
            Aside.TabControl = MainTabControl;

            //增加页面到Main
            AddPage(new fpgOrderList(), (int)GlobalEnumVars.RptPageIndex.Page1000);
            AddPage(new fpgOrderDetail(), (int)GlobalEnumVars.RptPageIndex.Page1001);
            AddPage(new fpgOrderSum(), (int)GlobalEnumVars.RptPageIndex.Page1002);
            AddPage(new fpgPaymentDetail(), (int)GlobalEnumVars.RptPageIndex.Page1003);
            AddPage(new fpgPaymentSum(), (int)GlobalEnumVars.RptPageIndex.Page1004);
            AddPage(new fpgGiftSum(), (int)GlobalEnumVars.RptPageIndex.Page1005);
            AddPage(new fpgClassList(), (int)GlobalEnumVars.RptPageIndex.Page1006);
            AddPage(new fpgSysUserSum(), (int)GlobalEnumVars.RptPageIndex.Page1007);

            ////设置Header节点索引
            Aside.CreateNode("销售单据列表", (int)GlobalEnumVars.RptPageIndex.Page1000);
            Aside.CreateNode("商品销售明细", (int)GlobalEnumVars.RptPageIndex.Page1001);
            Aside.CreateNode("商品销售汇总", (int)GlobalEnumVars.RptPageIndex.Page1002);
            Aside.CreateNode("支付明细", (int)GlobalEnumVars.RptPageIndex.Page1003);
            Aside.CreateNode("支付汇总", (int)GlobalEnumVars.RptPageIndex.Page1004);
            Aside.CreateNode("商品销售分析", (int)GlobalEnumVars.RptPageIndex.Page1005);
            Aside.CreateNode("交班单明细", (int)GlobalEnumVars.RptPageIndex.Page1006);
            Aside.CreateNode("收银员汇总", (int)GlobalEnumVars.RptPageIndex.Page1007);

            ////显示默认界面
            Aside.SelectFirst();
        }

        private void ubtn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Aside_MenuItemClick(TreeNode node, NavMenuItem item, int pageIndex)
        {
            mPageIndex = pageIndex;
            btn1_serach_Click(null,null);
        }

        private void btn1_serach_Click(object sender, EventArgs e)
        {
            SetParaToPage((int)GlobalEnumVars.ReportRequest.Query);
        }

        private void SetParaToPage(int type)
        {
            var posReport = new PosReportRequest()
            {
                starTime = CommFunc.ConvertToDateTime(dateTimeRange.DateTimeStar),
                endTime = CommFunc.ConvertToDateTime(dateTimeRange.DateTimeEnd),
                type = type,
            };
            switch (mPageIndex)
            {
                case (int)GlobalEnumVars.RptPageIndex.Page1000:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1000, posReport);
                    break;
                case (int)GlobalEnumVars.RptPageIndex.Page1001:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1001, posReport);
                    break;
                case (int)GlobalEnumVars.RptPageIndex.Page1002:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1002, posReport);
                    break;
                case (int)GlobalEnumVars.RptPageIndex.Page1003:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1003, posReport);
                    break;
                case (int)GlobalEnumVars.RptPageIndex.Page1004:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1004, posReport);
                    break;
                case (int)GlobalEnumVars.RptPageIndex.Page1005:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1005, posReport);
                    break;
                case (int)GlobalEnumVars.RptPageIndex.Page1006:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1006, posReport);
                    break;
                case (int)GlobalEnumVars.RptPageIndex.Page1007:
                    SendParamToPage((int)GlobalEnumVars.RptPageIndex.Page1007, posReport);
                    break;
            }
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            SetParaToPage((int)GlobalEnumVars.ReportRequest.Export);
        }
    }
}
